// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var AL_GAME_HUA_OnlineGiftData = require("./AL_GAME_HUA_OnlineGiftData");
// var h = cc._decorator;
// var _ = h.ccclass;
// var P = h.property;
// var g =
//     (h.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.toggle_pop = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.zhixing_chushihua_chuli = function () {};
//         t.prototype.start = function () {
//             this.toggle_pop.isChecked = !AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance().dailyRewardPop;
//         };
//         t.prototype.onEnable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !0
//             });
//         };
//         t.prototype.onDisable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !1
//             });
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             var n = this;
//             switch (t) {
//                 case "close":
//                     this.close();
//                     break;
//                 case "share":
//                     AL_GAME_HUA_Common.Common.share({
//                         location: AL_GAME_HUA_Define.Define.SHARE_LOCATION.LOGIN,
//                         type: 3,
//                         success: function () {
//                             AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance().dailyReward = !0;
//                             AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                                 rewards: [
//                                     {
//                                         goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
//                                         num: 1
//                                     }
//                                 ]
//                             });
//                             n.close();
//                             AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                                 source: AL_GAME_HUA_EventConfig.AssetsSource.login,
//                                 action: AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                                 goodsList: [
//                                     {
//                                         goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
//                                         num: 1
//                                     }
//                                 ]
//                             });
//                         }
//                     });
//                     break;
//                 case "toggle_pop":
//                     var o = this.toggle_pop.isChecked;
//                     AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance().dailyRewardPop = !o;
//             }
//         };
//         __decorate([P(cc.Toggle)], t.prototype, "toggle_pop", void 0);
//         return __decorate([_], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = g;


// 引入所需模块
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
const AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
const AL_GAME_HUA_OnlineGiftData = require("./AL_GAME_HUA_OnlineGiftData");

// Cocos Creator 装饰器
const { ccclass, property, menu } = cc._decorator;

/**
 * 游戏相关的类
 */
@ccclass
class GamePopup extends AL_GAME_HUA_PopupSelf.default {

    @property(cc.Toggle)
    toggle_pop = null;

    // 初始化方法
    zhixing_chushihua_chuli() {}

    // 生命周期 start 方法
    start() {
        const onlineGiftData = AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance();
        this.toggle_pop.isChecked = !onlineGiftData.dailyRewardPop;
    }

    // 当节点启用时触发的事件
    onEnable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: true
        });
    }

    // 当节点禁用时触发的事件
    onDisable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: false
        });
    }

    /**
     * 处理按钮回调
     * @param {Event} event - 事件对象
     * @param {string} type - 操作类型
     */
    handle_button_callback(event, type) {
        switch (type) {
            case "close":
                this.close();
                break;
            case "share":
                this.handleShare();
                break;
            case "toggle_pop":
                this.togglePop();
                break;
        }
    }

    // 处理分享的行为
    handleShare() {
        const common = AL_GAME_HUA_Common.Common;
        const onlineGiftData = AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance();

        common.share({
            location: AL_GAME_HUA_Define.Define.SHARE_LOCATION.LOGIN,
            type: 3,
            success: () => {
                onlineGiftData.dailyReward = true;
                this.createReceive();
                this.reportAssetOutput();
                this.close();
            }
        });
    }

    // 创建奖励
    createReceive() {
        AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
            rewards: [
                {
                    goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
                    num: 1
                }
            ]
        });
    }

    // 报告资产输出
    reportAssetOutput() {
        AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
            source: AL_GAME_HUA_EventConfig.AssetsSource.login,
            action: AL_GAME_HUA_EventConfig.AssetsAction.share_get,
            goodsList: [
                {
                    goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
                    num: 1
                }
            ]
        });
    }

    // 切换弹出状态
    togglePop() {
        const onlineGiftData = AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance();
        onlineGiftData.dailyRewardPop = !this.toggle_pop.isChecked;
    }
}

exports.default = GamePopup;